#ifndef __LINDRIVER_H
#define __LINDRIVER_H

#include "stm32f10x.h"            // Device header

#define  LIN_MASTER_IRQHandler 		 	 USART1_IRQHandler  //串口1中断定义
#define  LIN_BUFFER_SIZE                 64

//LIN消息ID类型
typedef enum{ 
	MASTER_BREAK = 0, //同步间隔
    MASTER_WRITE,     //主机写
    MASTER_READ		  //主机读
}LIN_MSG_IDType;	

//LIN错误代码
typedef enum{ 
	LIN_OK = 0, 
	FIFO_VOID,
	SYNC_ERR, 
	PID_ERR, 
	CHECK_ERR, 
	NO_RESPONES, 
	FORMAT_ERR
}LIN_ERROR_Code;	


//LIN接收状态
typedef enum{ 
	BREAK_GET = 0,
	SYNCH_GET,
	PID_GET,
	MSG_GET,
	CHECKSUM_GET, 
}LIN_RxState; 

//LIN消息结构
typedef struct{
    uint8_t Sync;         //同步段：固定值0x55
	uint8_t FrameID;      //帧ID
    uint8_t PID;          //PID
    uint8_t DataLen;      //LIN数据段有效字节数
    uint8_t Data[8];      //数据段(LIN规定数据长最多8字节)
    uint8_t Checksum;     //校验和
	LIN_MSG_IDType IdType;
}LIN_MSG;

void LIN_TimOutCmd(TIM_TypeDef* TIMx, FunctionalState NewState);
void LIN_ErrorCode(LIN_ERROR_Code ErrorCode);
extern LIN_MSG_IDType  FrameIDType[64]; 
void LIN_ErrorCheck(LIN_ERROR_Code ErrorCode);
void LIN_SendBreak(USART_TypeDef* USARTx);
void LIN_SendBytes(USART_TypeDef* USARTx,uint8_t* pData,uint8_t DataLen);
void LIN_SendMsg(USART_TypeDef* USARTx,uint8_t FrameID,uint8_t* pData,uint8_t DataLen, LIN_MSG_IDType IDType);
void LIN_MasterRxMsg(uint8_t Data);
uint8_t LIN_GetPID(uint8_t FrameID);
uint8_t LIN_GetChecksum(uint8_t PID, uint8_t* pData,uint8_t DataLen);

#endif
